package com.b2bpsssm.controller.sysmanage;/**
 * @author JunYu
 * @create 2022-08-13--15:27
 */

import com.b2bpsssm.common.R;
import com.b2bpsssm.pojo.SysUser;
import com.b2bpsssm.simulate.GenerateSysUsers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

/**
 * @program: B2BPSSMSystem
 * @description: 员工管理相关控制器
 * @author: JunYu
 * @create: 2022-08-13 15:27
 **/
@EnableSwagger2
@Controller
@RequestMapping(value = "/sys_user")
@Api(value = "员工管理", tags = "员工管理api")
public class SysUserController {

    //添加员工接口
    @RequestMapping(value = "/addUser", method = RequestMethod.POST)
    @ResponseBody
    //Swagger配置
    //Swagger配置
    @ApiOperation(value = "添加员工接口", notes = "添加角色接口，传入原型图所需参数", httpMethod = "post", response = R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "SysUser", value = "原型图中所需参数", paramType = "Object", dataType = "String", required = true)
            }
    )
    public R addUser(@RequestBody SysUser sysUser) {
        sysUser.setRole_id(1);
        R r = new R();
        r.setCode(200);
        r.setMassage("添加成功,员工为" + sysUser);
        return r;
    }

    //删除员工接口
    @RequestMapping(value = "/delUserById", method = RequestMethod.POST)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "删除员工接口", notes = "通过员工id删除员工", httpMethod = "post", response = R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "员工id", paramType = "int", dataType = "String", required = true)
            }
    )
    public R delUser(@RequestParam("id") int id) {
        R r = new R();
        r.setCode(200);
        r.setMassage("删除成功，员工id号为" + id);
        return r;
    }

    //批量删除员工接口
    @RequestMapping(value = "/batchDelUsers", method = RequestMethod.POST)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "批量删除员工", notes = "传入id数组批量删除员工", httpMethod = "", response = R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "ids", value = "员工id数组", paramType = "List<Integer>", dataType = "String", required = true)
            }
    )
    public R batchDelUsers(@RequestBody List<Integer> ids) {

        R r = new R();
        r.setCode(200);
        r.setMassage("批量删除成功,删除的id号有" + ids);
        return r;
    }

    //查询所有员工
    @RequestMapping(value = "/findUserList", method = RequestMethod.GET)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "查询所有角色", notes = "输入当前页码和页面长度来查询所有角色", httpMethod = "get", response = R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "currentPage", value = "当前页码", paramType = "int", dataType = "String", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "页码长度", paramType = "int", dataType = "String", required = true)
            }
    )
    public R findUserList(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        System.out.println("当前页面为" + currentPage);
        R r = new R();
        r.setCode(200);
        r.setMassage("查询所有员工成功");
        r.setData(GenerateSysUsers.generateSysUserList(pageSize));
        return r;
    }

    //导出所有员工
    @RequestMapping(value = "/exportUserLIst", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "导出所有员工", notes = "导出所有员工，不需要传入任何参数", httpMethod = "get", response = R.class)
    public R exportUserLIst() {
        R r = new R();
        r.setCode(200);
        r.setMassage("导出员工成功");
        return r;
    }

    //根据员工条件查询角色
    @RequestMapping(value = "/findUserInUncertain", method = RequestMethod.GET)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "根据员工条件查询员工", notes = "输入三种条件来查询对应员工", httpMethod = "", response = R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "role_id", value = "角色的id，若未输入，则默认为-1", paramType = "int", dataType = "String", required = true),
                    @ApiImplicitParam(name = "sto_id", value = "所属店铺id，若未输入，则默认为-1", paramType = "int", dataType = "String", required = true),
                    @ApiImplicitParam(name = "user_name", value = "员工姓名", paramType = "String", dataType = "String", required = true)
            }
    )
    public R findUserInUncertain(@RequestParam(value = "role_id", required = false, defaultValue = "-1") long role_id, @RequestParam(value = "sto_id", required = false, defaultValue = "-1") long sto_id, @RequestParam(value = "user_name", required = false) String user_name) {
        R r = new R();
        r.setCode(200);
        r.setMassage("查询成功" + "查询的角色id为" + role_id);
        r.setData(GenerateSysUsers.generateSysUserList(3));
        return r;
    }

    //编辑员工信息
    @RequestMapping(value = "/updateUserById", method = RequestMethod.POST)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "编辑员工信息", notes = "编辑员工信息", httpMethod = "post", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "SysUser", value = "原型图中所需参数", paramType = "Object", dataType = "String", required = true)
            }
    )
    public R updateUserById(@RequestBody SysUser sysUser) {
        R r = new R();
        r.setCode(200);
        r.setMassage("编辑员工成功");
        return r;
    }

    //修改员工状态
    @RequestMapping(value = "updateUserStatus",method = RequestMethod.POST)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "修改员工状态", notes = "通过员工id修改员工状态", httpMethod = "post", response = R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "员工id", paramType = "int", dataType = "String", required = true),
                    @ApiImplicitParam(name = "status", value = "状态编码", paramType = "int", dataType = "String", required = true)
            }
    )
    public R updateUserStatus(long id, byte status) {
        R r = new R();
        r.setCode(200);
        r.setMassage("编辑员工成功");
        return r;
    }

}
